package com.kun.portal.webframe.controller;

import com.kun.portal.webframe.po.FlightPlanePo;
import com.kun.portal.webframe.po.IndustryLoadPo;
import com.kun.portal.webframe.service.AircraftPreloadingService;
import com.kun.portal.webframe.service.FlightPlaneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2018/6/29.
 * 飞机配载
 */
@Controller
@RequestMapping({"/api/aircraftPreloading"})
public class AircraftPreloadingController {
    @Autowired
    private AircraftPreloadingService aircraftPreloadingService;
    @Autowired
    private FlightPlaneService flightPlaneService;
    @InitBinder
    public void intDate(WebDataBinder binder){
        DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }
    @RequestMapping(
            value = {"/saveIndustryLoadPo"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    @Transactional
    public IndustryLoadPo save(@RequestBody FlightPlanePo flightFlanePo) {
        IndustryLoadPo industryLoadPo =aircraftPreloadingService.saveIndustryLoadPo(flightFlanePo.getIndustryLoadPo());
        flightFlanePo.setIndustryLoadPo(industryLoadPo);
        flightPlaneService.save(flightFlanePo);
        return industryLoadPo;
    }




}
